
#pragma once

#include <stddef.h>

#if defined(QL_ENABLE_MEM_DEBUG) && defined(_MSC_VER)
#define QL_DBG_MEM_IMPL

#include <crtdbg.h>
#include <string.h>

#define ql_malloc(c, s)     _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
#define ql_realloc(c, p, s) _realloc_dbg( p, s, _NORMAL_BLOCK, __FILE__, __LINE__ )
#define ql_free(p)          _free_dbg( p, _NORMAL_BLOCK )

void * ql_dbg_mallocz_impl( size_t s, const char * file, int line );
#define ql_mallocz(c, s)           ql_dbg_mallocz_impl( s, __FILE__, __LINE__ )

void ql_dump_mem_leaks();

#else

struct AllocContext;

void * ql_malloc( struct AllocContext * c, size_t size );
void * ql_mallocz( struct AllocContext * c, size_t size );
void * ql_realloc( struct AllocContext * c, void * ptr, size_t size );
void ql_free( void * ptr );

static INLINE void ql_dump_mem_leaks()
{}

#endif
